package io.gitee.hefren.hhconfig.client.beans;

import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;

/**
 * @Date 2024/6/1
 * @Author lifei
 */
public class ConfigsMeta {
    private String app;
    private String env;
    private String namespace;
    private String configServer;

    public ConfigsMeta() {
    }

    public ConfigsMeta(String app, String env, String namespace, String configServer) {
        this.app = app;
        this.env = env;
        this.namespace = namespace;
        this.configServer = configServer;
    }

    public String genKey() {
        return Strings.lenientFormat("%s_%s_%s", this.getApp(), this.getEnv(), this.getNamespace());
    }

    public String listPath() {
        return path("list");
    }

    public String versionPath() {
        return path("version");
    }
    public String deferredResultVersionPath() {
        return path("deferredResultVersion");
    }


    private String path(String context) {
        return Strings.lenientFormat("%s/hhConfigServerController/%s?capp=%s&cenv=%s&cnamespace=%s",
                this.getConfigServer(), context, this.getApp(), this.getEnv(), this.getNamespace());
    }

    public String getApp() {
        return app;
    }

    public void setApp(String app) {
        this.app = app;
    }

    public String getEnv() {
        return env;
    }

    public void setEnv(String env) {
        this.env = env;
    }

    public String getNamespace() {
        return namespace;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public String getConfigServer() {
        return configServer;
    }

    public void setConfigServer(String configServer) {
        this.configServer = configServer;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(ConfigsMeta.class)
                .add("app", app)
                .add("env", env)
                .add("namespace", namespace)
                .add("configServer", configServer)
                .toString();
    }
}
